package com.sumainfor.zuul.service.impl;

import com.qiniu.util.Json;
import com.sumainfor.common.Constants;
import com.sumainfor.common.entity.ParentDeptVo;
import com.sumainfor.common.entity.SysUserVo;
import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.ComUtils;
import com.sumainfor.zuul.dao.UtilsMapper;
import com.sumainfor.zuul.dao.ZfeignMapper;
import com.sumainfor.zuul.service.ZfeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ZfeignServiceImpl implements ZfeignService {

    @Autowired
    private ZfeignMapper zfeignMapper;
    @Autowired
    private UtilsMapper utilsMapper;
    /**
     * 根据服务管家的员工编号查询服务管家的姓名
     * @param params
     * @return
     */
    @Override
    public List<Map<String, Object>> getButlerName(Map<String, Object> params) {
        return zfeignMapper.getButlerName(params);
    }
    /**
     * 市场部经理分配服务中心，根据部门编号查询服务中心信息
     */
    @Override
    public List<Map<String, Object>> getDeptNameByDeptId(Map<String,Object> params) {
        return zfeignMapper.getDeptNameByDeptId(params);
    }

    /**
     *房源上架详情查询房源的收房专员、归属服务中心、服务管家
     */
    @Override
    public Map<String, Object> getHousingInfoName(Map<String, Object> params) {
        Map<String,Object> map=new HashMap<String,Object>();
        if(params.get("SysUserId")!=null){//获取房源服务管家的信息
            params.put("user_id",params.get("SysUserId").toString());
            map=zfeignMapper.getSysUserName(params);
            if (map!=null){
                params.putAll(map);
            }
        }
        if(params.get("InclusionId")!=null){//获取房源收房专员的信息
            params.put("user_id",params.get("InclusionId").toString());
            map=zfeignMapper.getUserName(params);
            if (map!=null){
                params.put("InclusionName",map.get("name").toString());
            }
        }
        if(params.get("MiId")!=null){//获取房源所属的服务中心
            params.put("dept_id",params.get("MiId").toString());
            map=zfeignMapper.getDeptName(params);
            if (map!=null){
                params.put("MiName",map.get("name").toString());
            }
        }
        return params;
    }

    /**
     *市场部经理房源定价列表查询服务中心和定价人信息
     */
    @Override
    public Map<String, Object> getHousingInfoNameFd(Map<String, Object> params) {
        System.out.println("房源定价接受到参数:"+params);

        Map<String,Object> map=new HashMap<String,Object>();
        if(params.get("midList")!=null){//获取房源所属的服务中心
            params.put("idList",params.get("midList"));
            System.out.println("查询之前的参数:"+params);
            List<Map<String,Object>> list=zfeignMapper.getDeptNameByDeptId(params);
            if (list!=null){
                map.put("MiIdList",list);
            }
            System.out.println("返回给市场部的数据:"+list);
        }
        if(params.get("uidList")!=null){//获取房源所属的服务中心
            System.out.println("查询之前的参数:"+params);
            List<Map<String,Object>> list=zfeignMapper.getSysUserList(params);
            if (list!=null){
                map.put("UiIdList",list);
            }
            System.out.println("返回给市场部的数据:"+list);
        }
        return map;
    }
    /**
     *根据员工编号查询员工的姓名
     */
    @Override
    public Map<String, Object> getUserName(Map<String, Object> params) {
        return zfeignMapper.getUserName(params);
    }

    /**
     *签约时，获取输入房源编号的归属管家和归属中心
     */
    @Override
    public Map<String, Object> getUserDeptName(Map<String, Object> params) {
        Map<String,Object> map=new HashMap<String,Object>();
        //查询归属管家的姓名
        if (params.get("user_id")!=null){
            map=zfeignMapper.getUserName(params);
        }
        //查询房源的所属服务中心
        if (params.get("dept_id")!=null){
            Map<String,Object> deptMap=zfeignMapper.getDeptNameBy(params);
            map.putAll(deptMap);
        }
        return map;
    }

    /**
     * 转单池的查询转单人的信息
     */
    @Override
    public List<Map<String, Object>> getPuserListById(Map<String, Object> params) {
        return zfeignMapper.getButlerName(params);
    }
    /**
     * 运营部服务秘书账单管理根据编号查询管家的姓名
     */
    @Override
    public Map<String,Object> getSysUserBySysUserId(Map<String, Object> params) {
        Map<String,Object> map=new HashMap<String,Object>();
        List<Map<String,Object>> sList=zfeignMapper.getSysUserBySysUserId(params);
        //根据归属管家编号查询归属管家的姓名
        if (sList!=null){
            map.put("sysUserList",sList);
        }
        //查询租后主管账单审核的创建人信息
        List<Map<String,Object>> createList=zfeignMapper.getCreateUserList(params);
        System.out.println("查询到的创建人信息:"+createList);
        if (createList!=null){
            map.put("createList",createList);
        }
        return map;
    }
    /**
     * 租后主管查询报修人的信息
     */
    @Override
    public Map<String, Object> getRepairUserList(Map<String, Object> params) {
        Map<String,Object> map=new HashMap<String,Object>();
        //查询报修人的信息
        List<Map<String,Object>> rList=zfeignMapper.getRepairUserList(params);
        map.put("rList",rList);
        if(params.get("RepState").toString().equals("2")){
            List<Map<String,Object>> oList=zfeignMapper.getRepairOuserList(params);
            map.put("oList",oList);
        }
        System.out.println("map:"+map);
        return map;
    }
    /**
     *市场部经理查询房源定价人的信息
     */
    @Override
    public List<Map<String, Object>> getSysUserList(Map<String, Object> params) {
        return zfeignMapper.getSysUserList(params);
    }
    /**
     * 维修师傅查询维修工单的报修人信息
     */
    public Map<String, Object> getRuserList(Map<String,Object> params){
        Map<String,Object> map=new HashMap<String,Object>();
        //查询报修人的信息
        List<Map<String,Object>> rList=zfeignMapper.getRuserList(params);
        if (rList!=null){
            map.put("rList",rList);
        }
        //查询维修工单受理人的信息
        List<Map<String,Object>> sysList=(List<Map<String,Object>>)params.get("sysList");
        if (sysList.size()>0){
            List<Map<String,Object>> oList=zfeignMapper.getWeiUserList(params);
            if (oList!=null){
                map.put("oList",oList);
            }
        }
        System.out.println("map:"+map);
        return map;
    }
    /*维修师傅查询房源归属人的信息*/
    @Override
    public List<Map<String, Object>> getReapirSysUser(Map<String, Object> params) {
        return zfeignMapper.getReapirSysUser(params);
    }
    /**
     *租后主管管理人员查询服务秘书和服务管家
     */
    @Override
    public List<Map<String, Object>> getDiUserIdList(Map<String, Object> params) {
        return zfeignMapper.getDiUserIdList(params);
    }
    /**
     * 服务管家根据公司编号查询公司所在的市编号
     */
    public List<Map<String,Object>> getSysAreaList(Map<String,Object> params){
        return zfeignMapper.getSysAreaList(params);
    }
    /**
     *运营部服务管家退租的时候查询未缴费账单的录入人
     */
    public List<Map<String,Object>> getUsrList(Map<String,Object> params){
        return zfeignMapper.getUsrList(params);
    }
    /**
     * 查询服务中心下的全部角色列表
     */
    public List<Map<String,Object>> getWoUserIdList(Map<String,Object> params){
        return zfeignMapper.getWoUserIdList(params);
    }
    /**
     * 查询服务中心下的全部角色列表
     */
    public JsonResult getWoSaleIdList(Map<String,Object> params){
        JsonResult result=new JsonResult();
        if (params.get("role_id")==null){
            return result.putFailed("参数不正确");
        }
        List<Map<String,Object>> list=zfeignMapper.getWoUserIdList(params);
        if(list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     * 租后主管根据员工编号查询员工的信息
     */
    public Map<String,Object> getUserInfo(Map<String,Object> params){
        return zfeignMapper.getUserInfo(params);
    }
    /**
     * 服务管家查询受理人信息
     */
    public List<Map<String,Object>> getRepairOuserList(Map<String,Object> params){
        return zfeignMapper.getRepairOuserList(params);
    }
    /**
     * 新增消息提醒
     */
    public JsonResult addMessage(Map<String,Object> params){
        JsonResult result=new JsonResult();
        String UUID ="";
        Map<String,Object>uuid=utilsMapper.getUUID(new HashMap<String,Object>(){{
            put("uuid", "MeId");
            put("database", Constants.DATA_SOURCE_TCMKT);
            put("surface", "sys_message");
        }});
        if(uuid!=null){
            int number=Integer.valueOf(uuid.get("uuid").toString());
            UUID= ComUtils.getLocalTrmSeqNum("xx",number);
        }else{
            UUID=ComUtils.getLocalTrmSeqNum("xx",0);
        }
        params.put("MeId",UUID);//消息编号
        Integer count=zfeignMapper.addMessage(params);
        if (count>0){
            result.put(count);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     *市场部经理 服务中心管理查询服务中心的信息
     */
    @Override
    public JsonResult getSysDeptInfoList() {
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list= zfeignMapper.getSysDeptInfoList();
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     * 租后主管查询员工信息 （服务管家和服务秘书）
     */
    @Override
    public JsonResult getSysDeptRoleList(Map<String, Object> params) {
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list= zfeignMapper.getSysDeptRoleList(params);
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     *服务秘书审核账单查询账单的支付账号信息
     */
    @Override
    public JsonResult getTranInfoList(Map<String, Object> params) {
        System.out.println("网关接收到的参数:"+params);
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list=zfeignMapper.getTranInfoList(params);
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
}
